package com.itheima.thread.threadPool.scheduledExecutorService;

import com.itheima.thread.threadPool.executorService.MyRunnable;

import java.time.Instant;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Ethan Yankang
 * @Program: Interview
 * @Date: 2024-08-15 20:04
 **/
public class ScheduleExecutorServiceDemo {
    public static void main(String[] args) {
//        获取一个具有延迟任务的线程池对象
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(3);
//        创建多个任务对象，提交对象，每个任务延迟2秒执行
        for (int i = 1; i < 11; i++) {
            ses.schedule(new MyRunnable(i),2, TimeUnit.SECONDS);
        }
        Instant now = Instant.now();
        System.out.println("now = " + now);
        System.out.println("OVER");
    }
}